import scrapy
import json

class TestpostSpider(scrapy.Spider):
    name = 'testpost'
    allowed_domains = ['https://fanyi.baidu.com/sug']
    # post 请求如果没有参数，那么这个请求没有任何意义
    # 所以start_urls也就没用了
    # def parse(self, response):
    #     pass
    def start_requests(self):
        url = 'https://fanyi.baidu.com/sug'

        data={
            'kw':'final'
        }
        yield scrapy.FormRequest(url=url,formdata=data,callback=self.parse_second)

    def parse_second(self,response):
        content = response.text
        obj = json.loads(content,encodings='utf-8')
        print(obj)